﻿@model Olemas.ViewModels.HomeViewModel
@{
    ViewBag.Title = "Olemas";
    ViewBag.CurrentPage = "homePage";

}
@section AddToHead{
}

<div id ="filterBooks" class="filterItems">
    <label>Järjesta:</label>
    <img class="pacmanLoadingImage" style="display: none" src="~/Content/Site_Images/ajax-loader.gif" alt="oota.." />
    <a id="NewestFirst" class="filterItem">Uuemad enne</a>
    <a id="Title" class="filterItem">Pealkirja järgi</a>
    <a id="Author" class="filterItem">Autori nime järgi</a>
    <a id="Price" class="filterItem">Odavamad enne</a>
</div>
<hr />

<div id="recentBooksMain" class="recentBooksMain">
    @Html.Action("RecentBooks", "Home", new { page = 1, facId = @Model.FacultyId })
</div>

@section Sidebar{
    @Html.Action("Index", "Faculties", new { action = "Index", controller = "Home" })
}
@Html.Hidden("NumberOfPages", Model.NumberOfPages, new { id = "NumberOfPages" })
@Html.Hidden("CurrentPage", Model.CurrentPage, new { id = "CurrentPage" })
@Html.Hidden("FacultyId", Model.FacultyId, new { id = "FacultyId" })

<img class="loadingImage" style="display: none" src="~/Content/Site_Images/newLoading.gif" alt="oota.." />

@section AddToFooter
{
    <script type="text/javascript">
        $().ready(function () {
            //< --------------------Page variables ------------------------->
            Olemas.MaxPage = parseInt($("#NumberOfPages").val());
            Olemas.NextPage = parseInt($("#CurrentPage").val()) + 1;
            Olemas.FacultyId = parseInt($("#FacultyId").val());
            Olemas.ActionLink = '@Url.Action("RecentBooks", "Home")';
            Olemas.DivToUpdate = '#recentBooksMain';
            //< ------------------------------------------------------------>
            
            //< --------------------Page functions-------------------------->
            Olemas.HighlightFaculty();
            Olemas.CheckPages();
            Olemas.HighlightFilter($("#NewestFirst"));
            //< ------------------------------------------------------------>

            //< ------------------------Events------------------------------>
            $(document).on("click", ".filterItem", function () {
                Olemas.HighlightFilter($(this));
                Olemas.Ordering = $(this).attr("id");
                Olemas.NextPage = 2;
                Olemas.OrderItems();
            });
            
            $(document).on("click","#loadNextBooks", function () {
                if ($(this).text() == "↑ Kõik vaadatud. Tagasi üles ↑") {
                    $('html, body').animate({ scrollTop: 0 }, 'slow');
                }
                else {
                    Olemas.LoadMoreItems();
                }
            });

            $(window).scroll(
                $.throttle(800, Olemas.ScrollLoad));
            //< ------------------------------------------------------------>
            
        });
    </script>
}
